﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.SharePoint;
using Xodeuz.SP.Common;

namespace TestApplication
{
    public class TaskItem : ListItemModelBase
    {
        [Field("PercentComplete", SPFieldType.Number)]
        public double PercentageCompleted { get; set; }

        [Field("AssignedTo", SPFieldType.User)]
        public string AssignedTo { get; set; }

        [Field("DueDate", SPFieldType.DateTime)]
        public DateTime DueDate { get; set; }

        public TaskItem() : base(){}
        public TaskItem(Guid s, Guid w, Guid l) : base(s, w, l) { }
    }

    [ListTitle("Test List", SPListTemplateType.GenericList)]
    public class TestItem : ListItemModelBase
    {
        [Field("Somefield", SPFieldType.Text)]
        public string Field1 { get; set; }

        [Field("Datefield", SPFieldType.DateTime)]
        public DateTime Field2 { get; set; }
    }

    public class Program
    {
        static void Main(string[] args)
        {
            using(SPSite site = new SPSite("http://portal.dev.com"))
            using (SPWeb web = site.OpenWeb())
            {
                SPQuery query = new SPQuery{ Query = "<Where><IsNotNull><FieldRef Name='ID' /></IsNotNull></Where>"};
                SPList list = web.Lists.TryGetList("Tasks");

                var items = list.GetItems<TaskItem>(query);

            }
            Console.Read();
        }

    }
}
